"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/11/6 10:42
@Description :  线程的使用
线程锁
"""
import threading
import time
from threading import Thread

count = 0

#  线程锁
lock = threading.Lock()


def add():
    # 上锁
    lock.acquire()
    global count
    temp = count
    temp += 1
    count = temp
    time.sleep(0.2)
    print(count)
    # 释放锁
    lock.release()


if __name__ == '__main__':
    for i in range(100):
        t = Thread(target=add)
        t.start()
